package edu.unc.lensblaster.flickr;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Button;

public class WebAuthentication extends Activity {

	
	
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        
        setContentView(R.layout.authentication);
        Intent i = this.getIntent();
        Bundle b = i.getExtras();
        String url = b.getString(android.app.SearchManager.QUERY);
        url = url.replace("www.flickr.com", "m.flickr.com");
        WebView wv = (WebView)findViewById(R.id.webview);
        wv.setWebViewClient(new WebViewClient(){
        	
        	@Override
        	public boolean shouldOverrideUrlLoading(WebView view, String url){
        		
        		// Don't leave the WebView
        		return false;
			}
        });
        
        WebSettings ws = wv.getSettings();
        ws.setJavaScriptEnabled(true);
        
        //wv.loadDataWithBaseURL("fake://fake/", url, "text/html", "UTF-8", null);
        wv.loadUrl(url);
        
        android.util.Log.d("lens",url);
        
        Button backButton = (Button)findViewById(R.id.finish);
        backButton.setOnClickListener(new View.OnClickListener() {

        	public void onClick(View view) {
        	    setResult(RESULT_OK);
        	    finish();
        	}
          
        });
        
    }
 
}
